include eighth\bytecode_zp_y_dtc.s
include eighth\asmroutines.s
include nmientry.s

; PC lands here from startup routine

	poke PPU_CTRL, $00
	poke PPU_MASK, $00

	; PPU initialization
;	jsr testppuinit

	lda #$1E
	sta PPU_MASK_VAR

	init_vm
	jsr script_init

	poke PPU_CTRL, $B0  ; 8x16 sprites, spr patterns in bank 0, bg patterns in bank 1

	lda PPU_MASK_VAR
	sta PPU_MASK


; Endless loop
loop_start:
	cmp FRAMECNT
	beq loop_start
	lda FRAMECNT
	pha

	lda #0
;	sta OAM_PTR    ; instead we're going to just let it cycle around and around
	jsr poll_pad

; fast clear oambuf
	ldy #$20-4
	lda #$ff
-
	sta OAM_BUF,y
	sta OAM_BUF+64,y
	sta OAM_BUF+128,y
	sta OAM_BUF+192,y
	sta OAM_BUF+32,y
	sta OAM_BUF+32+64,y
	sta OAM_BUF+32+128,y
	sta OAM_BUF+32+192,y
	dey
	dey
	dey
	dey
	bpl -

	poke PPU_MASK, $5E

	jsr script_frame

	poke FORCED_BLANK, 0
	lda PPU_MASK_VAR
	sta PPU_MASK

	pla
	jmp loop_start


vblank:
	rts



include manualscript_dtc.s

;------------------------------------------------------------------------------------------------
; data


org $FFFA
	.dw nmi	;$fffa vblank nmi
	.dw start	;$fffc reset
	.dw irq	;$fffe irq / brk


